package baidu.reader.common.ui.components
{
    import baidu.lib.utils.*;
    import baidu.reader.common.*;
    import baidu.ui.controls.*;
    import baidu.ui.events.*;
    import baidu.ui.managers.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;

    public class PageNumber extends Sprite
    {
        private var _displayTextField:TextField;
        private var displayTextFormat:TextFormat;
        private var displayTmplate:String = "<b>${0}</b>/${1}ҳ";
        private var _currentPage:int = 0;
        private var _totalPage:int = 0;
        private var jumpButton:Button;

        public function PageNumber()
        {
            this._displayTextField = new TextField();
            this.displayTextFormat = new TextFormat("Microsoft Yahei,微软雅黑,黑体", 14, 5516307);
            this.addNumberTxt();
            return;
        }

        public function set enabled(param1:Boolean) : void
        {
            this.jumpButton.visible = param1;
            this.mouseEnabled = param1;
            this.mouseChildren = param1;
            return;
        }

        private function addNumberTxt() : void
        {
            this.displayTextFormat.align = TextFormatAlign.RIGHT;
            this._displayTextField.autoSize = TextFieldAutoSize.RIGHT;
            this._displayTextField.selectable = false;
            this._displayTextField.mouseEnabled = false;
            this._displayTextField.multiline = false;
            this._displayTextField.defaultTextFormat = this.displayTextFormat;
            this._displayTextField.filters = [new BlurFilter(0, 0, 0)];
            addChild(this._displayTextField);
            this.jumpButton = new Button();
            this.jumpButton.setStyle("skin", ResourceFactory.JumpButtonSkin);
            addChild(this.jumpButton);
            this.jumpButton.y = 4;
            this.jumpButton.useHandCursor = true;
            this.refresh();
            var _loc_1:* = TooltipManager.getInstance();
            var _loc_2:* = new Tooltip();
            _loc_2.setStyle("skin", ResourceFactory.TipBackground);
            _loc_2.setStyle("padding", 5);
            _loc_1.defaultRender = _loc_2;
            _loc_1.register(this, "跳转");
            this.useHandCursor = true;
            this.buttonMode = true;
            this.addEventListener(MouseEvent.CLICK, this.jumpClickHandler);
            return;
        }

        private function jumpClickHandler(event:MouseEvent) : void
        {
            dispatchEvent(new ReaderEvent(ReaderEvent.SHOW_PAGE_NUMBER_INPUT));
            return;
        }

        private function refresh() : void
        {
            this._displayTextField.htmlText = StringTemplate.output(this.displayTmplate, this._currentPage, this.totalPage);
            this.jumpButton.x = this._displayTextField.width + this._displayTextField.x + 6;
            graphics.clear();
            graphics.beginFill(0, 0);
            graphics.drawRect(0, 0, width, height);
            dispatchEvent(new BUIEvent(BUIEvent.SIZE_CHANGE, true));
            return;
        }

        public function get currentPage() : int
        {
            return this._currentPage;
        }

        public function set currentPage(param1:int) : void
        {
            this._currentPage = param1;
            this.refresh();
            return;
        }

        public function get totalPage() : int
        {
            return this._totalPage;
        }

        public function set totalPage(param1:int) : void
        {
            this._totalPage = param1;
            this.refresh();
            return;
        }

    }
}
